package com.homewoek;

import jdk.internal.util.xml.impl.Input;

import java.io.*;

/**
 * @Author:Ren2048
 * @Date:2021/8/27
 * @Description:com.edu
 * @Version:1.8.0_261
 */
public class Stream {
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        File fromFile = new File("F:/test1.txt");
        File toFile = new File("F:/test2.txt");

        InputStream is = null;
        OutputStream os = null;
        try{
            is = new FileInputStream(fromFile);
            os = new FileOutputStream(toFile);

            int count = is.read();
            while(count!=-1){
                os.write(count);
                count = is.read();
            }
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }catch (IOException ie){
            ie.printStackTrace();
        }finally {
            try{
                is.close();
                os.close();
            }catch (IOException ie){
                ie.printStackTrace();
            }
            long endTime = System.currentTimeMillis();
            long costTime = endTime - startTime;
            System.out.println("复制文件完成，总共耗时："+costTime+"ms");
        }
    }
}
